package com.xsomnus.grpc.consumer;

import com.xsomnus.grpc.lib.GreeterGrpc;
import com.xsomnus.grpc.lib.GreeterOuterClass;
import io.grpc.Channel;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/7/3 0003 10:01
 * - 才需学也,学需静也/非淡泊无以明志，非宁静无以致远
 */
@Service
public class GrpcClientService {

    @GrpcClient("grpc-provider")
    private Channel serverChannel;


    public String sendMessage(String name) {
        final GreeterGrpc.GreeterBlockingStub greeterBlockingStub = GreeterGrpc.newBlockingStub(serverChannel);
        final GreeterOuterClass.HelloReply response = greeterBlockingStub.sayHello(GreeterOuterClass.HelloRequest.newBuilder().setName(name).build());
        return response.getMessage();
    }

}
